/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.taskplugins  
 */
package com.apache.bid.service.taskplugins;

import java.util.List;

import com.apache.api.api.TimeTaskService;
import com.apache.api.manager.PluginConnector;
import com.apache.api.manager.ProxyManager;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.Constant;
import com.apache.bid.entity.BidItem;
import com.apache.bid.manager.BidItemManager;
import com.apache.cache.util.Validator;

/**
 * description:  将完成的标的移动到历史表
 * @author Hou Dayu 创建时间：2016-3-29  
 * 
 */
public class RemoveItemHistoryTask implements PluginConnector, TimeTaskService {

	private transient static boolean RemoveItemHistory = true;

	private BidItemManager bidItemManager;
	private ProxyManager wbdProxyCacheManager;

	public boolean run() {
		try {
			execute(new ParamsVo());
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		try {
			if (RemoveItemHistory) {
				RemoveItemHistory = false;
				BidItem bm = new BidItem();
				bm.setItemStatus(Constant.getInstance().getItemConfig("statusStop"));
				param.setObj(bm);
				param.setMethodKey("");
				List<BidItem> list = bidItemManager.getList(param);
				if (Validator.isEmpty(list))
					return entity;
				try {
					ParamsVo vo = new ParamsVo();
					vo.setKey("removeItemHistory");
					for (BidItem item : list) {
						vo.setObj(item);
						wbdProxyCacheManager.saveInvoke(vo);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} finally {
			RemoveItemHistory = true;
		}
		return entity;
	}

	public void setBidItemManager(BidItemManager bidItemManager) {
		this.bidItemManager = bidItemManager;
	}

	public void setWbdProxyCacheManager(ProxyManager wbdProxyCacheManager) {
		this.wbdProxyCacheManager = wbdProxyCacheManager;
	}

}
